package com.pxst.agent.controller;

import com.github.pagehelper.Page;
import com.pxst.agent.entity.SysAgentCommissionSettings;
import com.pxst.agent.entity.SysAgents;
import com.pxst.agent.req.AgentCreatReq;
import com.pxst.agent.req.RateSettingCreateReq;
import com.pxst.agent.req.RateSettingReq;
import com.pxst.agent.resp.RateSettingResp;
import com.pxst.agent.service.SysAgentCommissionSettingsService;
import com.pxst.agent.service.SysAgentsService;
import com.pxst.annotations.LogOperate;
import com.pxst.resp.ApiResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
* @author zarke
* @since 2023-09-25 10:19:52
*/
@Api(tags = "代理-抽成费率设定")
@RestController
@RequestMapping("/api/commission")
public class SysAgentCommissionSettingsController {

    @Autowired
    private SysAgentCommissionSettingsService sysAgentCommissionSettingsService;

    @GetMapping()
    @ApiOperation(value = "搜索")
    public ApiResp<Page<RateSettingResp>> getById(RateSettingReq rateSettingReq) {
        return sysAgentCommissionSettingsService.getCommission(rateSettingReq);
    }

    @PostMapping
    @ApiOperation(value = "新增设定")
    @LogOperate(operate = "新增设定", service = SysAgentsService.class, type = "add")
    @PreAuthorize("@ss.hasAnyPermissions('agent:commission:create')")
    public ApiResp<SysAgentCommissionSettings> create(@RequestBody RateSettingCreateReq rateSetting) {
        return sysAgentCommissionSettingsService.createRateSetting(rateSetting);
    }
}
